package GUI;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Graphics;
import java.util.Calendar;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import UserData.User_Management;
public class BarChart extends JFrame{
	private BarChart bc;
	private JPanel contentPane;
	private int UserListNumber = User_Management.Get_User_list.size();
	private Calendar cal;
	int baseline = 260;
	int Yaxis = 50;
	int time[]=new int[UserListNumber];
	String name[]=new String[UserListNumber];
	public void initVar(){
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 860, 600);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);

		contentPane.setBounds(100, 100, 860, 600);
		contentPane.setLayout(null);	
		cal = Calendar.getInstance(); //
	}
	public void set1(int timear[]){
		this.time=timear;
	}//get checked user time from main page by referencing User_Management
	public void set2(String namear[]){
		this.name=namear;
	}//get checked user name from main page by referencing User_Management
	public BarChart(int time[], String name[]){
		initVar();
		this.time=time;
		this.name=name;
		for(int i =0;i<UserListNumber;i++){
			if(name[i]==null){
				name[i]=User_Management.Now_User.getUser_Real_Name();
				time[i]=User_Management.Now_User.getLateTime();
			}
		}// find null that means unchecked user on main page
	}
	public void paint(Graphics g){
		g.drawLine(Yaxis, baseline, 600+Yaxis, baseline);
		for (int cnt = 1; cnt < 11; cnt++) {
			g.drawString(cnt*10 + "", 25, baseline - 20*cnt);  
			g.drawLine(Yaxis, baseline-20*cnt, 600+Yaxis, baseline - 20*cnt);
		}//draw background line
		g.drawString("over 100", 25, 10);  
		g.drawLine(Yaxis, 40, 600+Yaxis, 40);
		g.drawLine(Yaxis, 40, Yaxis, baseline);
		for(int i =0;i<UserListNumber;i++){
			g.drawString(name[i], 100+100*i, baseline+30);
			if(time[i]>0){
				g.fillRect(100, baseline - i*time[i], 10, i*time[i]*2);
				g.setColor(Color.RED);
				}
		}//draw bar use time array and name array
	}																																																				
}